package com.xca.znb.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class LocalDBHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "local.db";
    private static final int DATABASE_VERSION = 1 ;
    public static final String TABLE_LOCAL = "locals" ;
    public static final String LOCAL_ID = "id" ;
    public static final String LOCAL_USER_NAME = "name";
    public static final String LOCAL_USER_PHONE = "phone" ;
    public static final String LOCAL_ADDRESS = "local" ;
    public static final String LOCAL_TYPE = "type" ;
    public static final String LOCAL_LOGIN_PHONE = "login_phone" ;

    private static final String CREATE_TABLE_LOCAL = "CREATE TABLE " + TABLE_LOCAL +"("
            + LOCAL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT ," +
            LOCAL_USER_NAME + " TEXT ," +
            LOCAL_USER_PHONE + " TEXT ," +
            LOCAL_ADDRESS + " TEXT ," +
            LOCAL_TYPE + " TEXT ," +
            LOCAL_LOGIN_PHONE + " TEXT )";

    public LocalDBHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE_LOCAL);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS " + TABLE_LOCAL);
        onCreate(db);
    }
}
